package br.ufu.lsi.social.storage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import br.ufu.lsi.social.storage.model.User;
import br.ufu.lsi.social.storage.service.SocialService;

@Controller
public class UserController {
    
    @Autowired
    private SocialService socialService;
    
    @RequestMapping( value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public User test() {
        User u = new User();
        u.setScreenName( "userName" );
        u.setId( 1234 );
        return u;
    }
    
    @RequestMapping( value = "/users", method = RequestMethod.GET)
    @ResponseBody
    public Page<User> findUsers( @RequestParam("page") int page ) {
        Pageable pageable = new PageRequest(page, 10);
        Page<User> users = socialService.findAllUsers( pageable );
        return users;
    }

    
}
